package com.company;

public class TicketsThread implements Runnable{
    private int ticket=10;
    private int goumai=0;
    @Override
    public void run() {

            try {

                for (int i = 0; i < 10; i++) {
                    Thread.yield();
                    synchronized (this) {
                        if (ticket <= 0) {
                            break;
                        }
                        Thread.sleep(300);
                        ticket--;
                        goumai++;
                        System.out.println(Thread.currentThread().getName() + "抢到第" + goumai + "还有" + ticket + "张票");
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }



}
